﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QL_NOI_TRU
{
    public partial class frmYeuCauXetNghiem : DevExpress.XtraEditors.XtraForm
    {
        public frmYeuCauXetNghiem()
        {
            InitializeComponent();
        }
        public static string name = "";
        private void frmYeuCauXetNghiem_Load(object sender, EventArgs e)
        {
            //do du lieu vao lưới dich vu
            var kn = new Ketnoi(frmDangnhap.stringConn);
            gridControl1.DataSource = kn.ExcuteQuery("select * from DV_CAN_LAM_SANG");

            //lay ten nguoi dang nhap vao ten nguoi chi dinh
            txtnguoichidinh.Text = name;

            // đổ dữ liệu vào cbbMaBenhNhan
            var maBN = "select MA_BN,HOTEN from BENH_NHAN";
            SqlConnection conn = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cm = conn.CreateCommand();
            cm.CommandText = maBN;
            conn.Open();
            SqlDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                var newVariable = cbbMABenhNhan.Properties.Items.Add(String.Format("{0} | {1}", dr["MA_BN"], dr["HOTEN"]));
            }
            dr.Close();

            // đổ dữ liệu vào cbbNoiChiDinh
            var noi = "select MA_KHOA,TEN_KHOA from KHOA";
            SqlConnection con = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = noi;
            con.Open();
            SqlDataReader dr1 = cmd.ExecuteReader();
            while (dr1.Read())
            {
                var newVariable = cbbNoiChiDinh.Properties.Items.Add(String.Format("{0} | {1}", dr1["MA_KHOA"], dr1["TEN_KHOA"]));
            }


        }

        private void cbbNoiChiDinh_SelectedIndexChanged(object sender, EventArgs e)
        {
            var nhomDV = "select MADV,TENDV from DV_CAN_LAM_SANG";
            SqlConnection con = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = nhomDV;
            con.Open();
            SqlDataReader dr1 = cmd.ExecuteReader();
            while (dr1.Read())
            {
                var newVariable = cbbNoiChiDinh.Properties.Items.Add(String.Format("{0} | {1}", dr1["MADV"], dr1["TENDV"]));
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            var ht = "select * from BENH_NHAN where MA_BN = '"+tbMABenhnhan.Text+"'";
           /* string ns = String.Format("select NGAYSINH from BENH_NHAN where MA_BN = '{0}'", tbMABenhnhan.Text);
            string GT = String.Format("select GIOITINH from BENH_NHAN where MA_BN = '{0}'", tbMABenhnhan.Text);
            string T = String.Format("select TUOI from BENH_NHAN where MA_BN = '{0}'", tbMABenhnhan.Text);
            string DC = String.Format("select DIACHI from BENH_NHAN where MA_BN = '{0}'", tbMABenhnhan.Text);
            var kn = new Ketnoi(frmDangnhap.stringConn);
            tbHoTen.Text = ht;
            tbNgaySinh.Text = ns;
            cbbGioiTinh.Text = GT;
            txtTuoi.Text = T;
            txtDiaChi.Text = DC;
            */

            SqlConnection con = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = ht;
            con.Open();
            SqlDataReader dr1 = cmd.ExecuteReader();
            while (dr1.Read())
            {
            //    var newVariable = cbbNoiChiDinh.Properties.Items.Add(String.Format("{0} | {1}", dr1["MADV"], dr1["TENDV"]));
                tbHoTen.Text = String.Format("{1}", dr1["HOTEN"]);
            }

        }

    }
}